package top.wilbert.collegelink.forum.controller;/**
 * @author augus
 * @create 2023-03-24-21:26
 */

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.wilbert.collegelink.forum.component.SocketClientDemo;

/**
 * @ClassName:ClientSocketController
 * @Description:
 * @author Augus
 * @date 2023/3/24 21:26
 * @Version 1.0
 **/
@RestController
@RequestMapping("forum/clientSocket")
public class ClientSocketController {
    @RequestMapping("/sendMsg/{toUserId}/{msg}")
    public void sendMsg(@PathVariable("toUserId") String toUserId, @PathVariable("msg") String msg) {
        //点赞通知
        SocketClientDemo.sendMsg("{\"type\":\"MESSAGE\",\"chat\":\"LIKE\",\"from\":\""+SocketClientDemo.getFromUserId()+"\",\"to\":\"" + toUserId + "\",\"message\":\"" + msg + "\"}");
    }

    @RequestMapping("/starClient/{userId}")
    public void starClient(@PathVariable("userId") String userId) {
        SocketClientDemo.open(userId);
    }

    @RequestMapping("/closeClient")
    public void closeClient() {
        SocketClientDemo.close();
    }
}
